package com.bytesizedhosting.api.android.darthcrap;

import java.util.ArrayList;

public class NullArgumentException extends IllegalArgumentException {
	private String strMessage;
	
	public NullArgumentException() {
		this.strMessage = "One or more non-nullable parameters had null provided instead.";
	}
	
	public NullArgumentException(int... arrProblemArguments) {
		String strMessage = "Argument" + (arrProblemArguments.length==1?"":"s") + " ";
		for (int intArgument=0; intArgument<arrProblemArguments.length; intArgument++) {
			if (intArgument != 0) {
				if (intArgument == arrProblemArguments.length - 1 && arrProblemArguments.length > 1) {
					strMessage += " and ";
				}
				else {
					strMessage += ",";
				}
			}
			strMessage += (arrProblemArguments[intArgument]);
		}
		strMessage += " are non-nullable parameters but had null provided.";
		this.strMessage = strMessage;
	}
	
	@Override
	public String getMessage() {
		return this.strMessage;
	}

	private static final long serialVersionUID = -1434356824631839155L;

	public static void testArguments(Object... arrParameters) {
		ArrayList<Integer> lstInvalidArguments = new ArrayList<Integer>();
		for (int intIndex=0; intIndex<arrParameters.length; intIndex++) {
			if (arrParameters[intIndex] == null) {
				lstInvalidArguments.add(intIndex+1);
			}
		}
		if (lstInvalidArguments.size() > 0) {
			int[] arrInvalidArguments = new int[lstInvalidArguments.size()];
			for (int intArgument=0; intArgument<arrInvalidArguments.length; intArgument++) {
				arrInvalidArguments[intArgument] = lstInvalidArguments.get(intArgument);
			}
			throw new NullArgumentException(arrInvalidArguments);
		}
	}	
}